﻿#include "digitalkeyboard.h"

#include "ui_digitalkeyboard.h"

Digitalkeyboard::Digitalkeyboard(QWidget* parent) : QDialog(parent), ui(new Ui::Digitalkeyboard) {
  ui->setupUi(this);

  QString button_style(
      "QPushButton{border-image: url(:/pic/src/button/key.png);color: white;}"
      "QPushButton:hover{border-image: url(:/pic/src/button/key_hover.png);color: white;}"
      "QPushButton:pressed{border-image: url(:/pic/src/button/key_pressed.png);color: black;}");
  ui->pushButton_ok->setStyleSheet(button_style);
  ui->pushButton_cancle->setStyleSheet(button_style);
  ui->lineEdit_number->setPlaceholderText(" 数字输入");
}

Digitalkeyboard::~Digitalkeyboard() { delete ui; }

void Digitalkeyboard::setTheNumber(const QString& text) { ui->lineEdit_number->setText(text); }

QString Digitalkeyboard::getTheNumber() { return ui->lineEdit_number->text(); }

bool Digitalkeyboard::isOk() { return is_ok; }

void Digitalkeyboard::on_pushButton_num_1_clicked() { ui->lineEdit_number->insert("1"); }

void Digitalkeyboard::on_pushButton_num_2_clicked() { ui->lineEdit_number->insert("2"); }

void Digitalkeyboard::on_pushButton_num_3_clicked() { ui->lineEdit_number->insert("3"); }

void Digitalkeyboard::on_pushButton_num_4_clicked() { ui->lineEdit_number->insert("4"); }

void Digitalkeyboard::on_pushButton_num_5_clicked() { ui->lineEdit_number->insert("5"); }

void Digitalkeyboard::on_pushButton_num_6_clicked() { ui->lineEdit_number->insert("6"); }

void Digitalkeyboard::on_pushButton_num_7_clicked() { ui->lineEdit_number->insert("7"); }

void Digitalkeyboard::on_pushButton_num_8_clicked() { ui->lineEdit_number->insert("8"); }

void Digitalkeyboard::on_pushButton_num_9_clicked() { ui->lineEdit_number->insert("9"); }

void Digitalkeyboard::on_pushButton_ok_clicked() {
  is_ok = true;
  this->close();
}

void Digitalkeyboard::on_pushButton_cancle_clicked() {
  is_ok = false;
  this->close();
}

void Digitalkeyboard::on_pushButton_num_10_clicked() { ui->lineEdit_number->backspace(); }

void Digitalkeyboard::on_pushButton_num_11_clicked() { ui->lineEdit_number->insert("-"); }

void Digitalkeyboard::on_pushButton_num_12_clicked() { ui->lineEdit_number->clear(); }

void Digitalkeyboard::on_pushButton_num_13_clicked() { ui->lineEdit_number->insert("~"); }

void Digitalkeyboard::on_pushButton_num_0_clicked() { ui->lineEdit_number->insert("0"); }

void Digitalkeyboard::keyPressEvent(QKeyEvent* e) {
  if ((e->key() == Qt::Key_Enter) || (e->key() == Qt::Key_Return)) { on_pushButton_ok_clicked(); }
}
